package com.qf.fmall2204.product.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.fmall2204.constants.Constants;
import com.qf.fmall2204.product.entity.ProductParams;
import com.qf.fmall2204.product.service.IProductCommentsService;
import com.qf.fmall2204.product.service.IProductParamsService;
import com.qf.fmall2204.product.service.IProductService;
import com.qf.fmall2204.vo.CommontsCountResultVo;
import com.qf.fmall2204.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * <p>
 * 商品 商品信息相关表：分类表，商品图片表，商品规格表，商品参数表 前端控制器
 * </p>
 *
 * @author dong
 * @since 2023-04-21
 */
@CrossOrigin
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    IProductService productService;

    @Autowired
    IProductParamsService productParamsService;

    @Autowired
    IProductCommentsService productCommentsService;

    @GetMapping("/detail-commontscount/{id}")
    public ResultVo detailCommontscount(@PathVariable("id") Integer id){

//        CommontsCountResultVo result = productCommentsService.detailCommontscount(id);
        CommontsCountResultVo result = productCommentsService.detailCommontscountBetter(id);

        return new ResultVo(Constants.SUCCESS_CODE, "success", result);
    }


    @GetMapping("/detail-commonts/{id}")
    public ResultVo detailCommonts(@PathVariable("id") Integer id ,Integer pageNum,Integer limit){

        HashMap<String,Object> result = productCommentsService.detailCommonts(id,pageNum,limit);

        return new ResultVo(Constants.SUCCESS_CODE, "success", result);
    }


    @GetMapping("/detail-params/{id}")
    public ResultVo detailParams( @PathVariable("id") Integer id  ){

        ProductParams productParam = productParamsService.getOne(new QueryWrapper<ProductParams>().eq("product_id", id));

        return new ResultVo(Constants.SUCCESS_CODE, "success", productParam);

    }


    @GetMapping("/detail-info/{id}")
    public ResultVo detailInfo(@PathVariable("id") Integer id ){

        HashMap<String,Object> result = productService.detailInfo(id);

        return new ResultVo(Constants.SUCCESS_CODE,"success",result);
    }

}
